'use strict';

const { log } = require('console');
const { Controller } = require('egg');
const fs = require("fs");
const path = require("path");
class ImgController extends Controller {
  async zuopinxinxi() {
    const {
      ctx,
    } = this;
    // console.log(this.ctx.request.body)
    const {
      video,
      title,
      comment,
      auther,
      avatar,
      uid,
      zhuti,


    } = this.ctx.request.body
    const sql1 = `insert into workers (title,comment,zhuti,uid,video,auther,avatar) 
		values ("${title}","${zhuti}","${comment}","${uid}","${video}","${auther}","${avatar}")`
    const res = await this.ctx.app.mysql.query(sql1)
    ctx.body = {
      code: 20002,
      info: "注册成功",
    }
    // console.log(this.ctx.request.body)
  }


  async userdata() {
    const {
      ctx,
    } = this;
    console.log(this.ctx.request.body)
    const {
      uname,
      brithday,
      type,

      tel,
      pwd,
      gender,
      email,
      avatar,


    } = this.ctx.request.body;
    const sql2 = `insert into user (
			uname,
			brithday,
		   type,
		   tel,
		   pwd,
		   gender,
		   email,
		   avatar) 
	   values ("${uname}", "${brithday}","${type}","${tel}","${pwd}","${gender}","${email}","${avatar}")`
    const res = await this.ctx.app.mysql.query(sql2)
    ctx.body = {
      code: 20002,
      info: "注册成功",
    }
    console.log(this.ctx.request.body)
  }




  async single() {
    const {
      ctx,
    } = this
    console.log(this.ctx.request.body)
    const {wid}=this.ctx.request.body
    // console.log(this.ctx.request.body.wid)
    const sql4 = `SELECT shipin,uid,title,video,comment,zhuti,avatar,auther,dianzan from workers where wid="${wid}"`
    const res = await this.ctx.app.mysql.query(sql4)
    this.ctx.body = {
      code: 2010,
      info: res,
    };

  }





  async allclass() {
    const {
      ctx,
    } = this;
    console.log(this.ctx.request.query,66666)
    const sql3 = `SELECT wid,uid,title,video,comment,zhuti,avatar,auther,dianzan from workers `
    // console.log(sql3,9999999);
    const res = await this.ctx.app.mysql.query(sql3)
    console.log(res);
    this.ctx.body = {
      code: 2010,
      info: res,
    };

  }


  async sousuo() {
    const {
      ctx,
    } = this;
    console.log(this.ctx.request.body.data,666666666666666,"你好","年号你好")
    const sousuodata= this.ctx.request.body.data
    console.log(sousuodata);
    const sql3 = `SELECT wid,uid,title,video,comment,zhuti,avatar,auther,dianzan from workers where title like '%${sousuodata}%'`
    console.log(sql3,9999999);
    const res = await this.ctx.app.mysql.query(sql3)
    console.log(res);
    this.ctx.body = {
      code: 2010,
      info: res,
    };

  }
  // select count(*) from mysqlb_client where name like '%庆农%';




  async shijue() {
    const {
      ctx,
    } = this;
    // console.log(this.ctx.request.query,66666)
    const sql3 = `SELECT wid,uid,title,video,comment,zhuti,avatar,auther,dianzan from workers where zhuti="视觉/运营设计"`
    const res = await this.ctx.app.mysql.query(sql3)
    this.ctx.body = {
      code: 2010,
      info: res,
    };

  }

  async huihua() {
    const {
      ctx,
    } = this;
    // console.log(this.ctx.request.query,66666)
    const sql3 = `SELECT wid,uid,title,video,comment,zhuti,avatar,auther,dianzan from workers where zhuti="绘画插画"`
    const res = await this.ctx.app.mysql.query(sql3)
    this.ctx.body = {
      code: 2010,
      info: res,
    };

  }









  // 获取课程作者信息
  // async classxinxi() {
  // 	const {
  // 		ctx
  // 	} = this;
  // 	let {
  // 		uid
  // 	} = this.ctx.request.query
  // 	console.log(this.ctx.request.query,88888888)
  // 	let sql4 = `SELECT avatar,title,uname,video from user inner join workers on workers.uid=user.uid WHERE workers.uid=${uid}`
  // 	let res = await this.ctx.app.mysql.query(sql4)
  // 	this.ctx.body = {
  // 		code: 2010,
  // 		info: res
  // 	};

  // }


  // 获取课程作者信息
  // async classxinxi() {
  // 	const {
  // 		ctx
  // 	} = this;
  // 	let {
  // 		uid
  // 	} = this.ctx.request.query
  // 	console.log(this.ctx.request.query,88888888)
  // 	let sql4 = `SELECT avatar,title,uname,video from user inner join workers on workers.uid=user.uid WHERE workers.uid=${uid}`
  // 	let res = await this.ctx.app.mysql.query(sql4)
  // 	this.ctx.body = {
  // 		code: 2010,
  // 		info: res
  // 	};

  // }

  // async touxiangupload() {
  // 	const { ctx } = this;
  // 	console.log(6666, this.ctx.request.files)
  // 	let oldpath=this.ctx.request.files[0].filepath//服务器电脑c盘中
  // 	let imgname = path.basename(oldpath)
  // 	let newpath = __dirname + "/../public/upload/" + imgname
  // 	fs.renameSync(oldpath, newpath)
  // 	ctx.body = { code: 2000, info: "上传成功", url: "/upload/" + imgname };
  // }


  // async videoupload() {
  // 	const { ctx } = this;
  // 	console.log(6666, this.ctx.request.files)
  // 	let oldpath=this.ctx.request.files[0].filepath//服务器电脑c盘中
  // 	let imgname = path.basename(oldpath)
  // 	let newpath = __dirname + "/../public/upload/" + imgname
  // 	fs.renameSync(oldpath, newpath)
  // 	ctx.body = { code: 2000, info: "上传成功", url: "/upload/" + imgname };
  // }

}

module.exports = ImgController;







